package com.gangquan360.smartadmin.module.product.controller;

import com.gangquan360.smartadmin.common.domain.PageResultDTO;
import com.gangquan360.smartadmin.common.domain.ResponseDTO;
import com.gangquan360.smartadmin.constant.SwaggerTagConst;
import com.gangquan360.smartadmin.module.product.domain.dto.ProductDTO;
import com.gangquan360.smartadmin.module.product.domain.dto.ProductQueryDTO;
import com.gangquan360.smartadmin.module.product.service.ProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * [ 产品表 ]
 *
 * @author wiggin
 * @version 1.0
 * @company wiggin
 * @copyright (c) 2019 wigginInc. All rights reserved.
 * @date 2020-03-14 21:29:23
 * @since JDK1.8
 */
@RestController
@Api(tags = {SwaggerTagConst.Group2.PRODUCT_MANGER})
public class ProductController {

    @Autowired
    private ProductService productService;

    @ApiOperation(value = "分页查询产品表",notes = "@author wiggin")
    @PostMapping("/product/page/query")
    public ResponseDTO<PageResultDTO<ProductDTO>> queryByPage(@RequestBody ProductQueryDTO queryDTO) {
        return productService.queryByPage(queryDTO);
    }

    @ApiOperation(value = "添加产品表",notes = "@author wiggin")
    @PostMapping("/product/add")
    public ResponseDTO<String> add(@RequestBody @Valid ProductDTO addTO){
        return productService.add(addTO);
    }

    @ApiOperation(value="修改产品表",notes = "@author wiggin")
    @PostMapping("/product/update")
    public ResponseDTO<String> update(@RequestBody @Valid ProductDTO updateDTO){
        return productService.update(updateDTO);
    }


    @ApiOperation(value="删除产品表",notes = "@author wiggin")
    @GetMapping("/product/delete/{id}")
    public ResponseDTO<String> delete(@PathVariable("id") Long id){
        return productService.delete(id);
    }


    @ApiOperation(value="详情产品表",notes = "@author wiggin")
    @GetMapping("/product/detail/{id}")
    public ResponseDTO<ProductDTO> detail(@PathVariable("id") Long id){
        return productService.detail(id);
    }
}
